Module Math is a basic library for numerical computations. It offers the most frequently used functions and constants. For some additional functions, a transformation in terms of functions available in module Math is given.
Constants
PROCEDURE Pi (): REAL
PROCEDURE LPi (): LONGREAL
Returns an approximation of the value of pi.
result = 3.141592...
PROCEDURE Eps (): REAL
PROCEDURE LEps (): LONGREAL
Returns the machine epsilon for REAL and LONGREAL respectively. The machine epsilon eps is the smallest floating point number such that the sum 1.0
eps can be represented exactly in a REAL (or LONGREAL) variable. Usually, the machine epsilon is 2-m where m is the number of digits used to represent the mantissa of a floating point number. Note, that MathEps() is not necessarily the smallest floating point number with the property that its sum with 1.0 is greater than 1.0, and note also, that most floating point processors offer a higher internal precision than what can be represented within REAL and LONGREAL variables.
The arguments for all trigonometric and hyperbolic functions must be given in radians, and the inverse trigonometric and hyperbolic functions are calculated in radians (1 radian = 180/Pi degrees). At the end of this section a transformation table for additional trigonometric and hyperbolic functions is given which do not belong to the interface of the Math module, but which can easily be written in terms of the exported functions.
PROCEDURE Sin (x: REAL): REAL
PROCEDURE LSin (x: LONGREAL): LONGREAL
Returns the sine of x.
-1.0 <= result <= 1.0
PROCEDURE Cos (x: REAL): REAL
PROCEDURE LCos (x: LONGREAL): LONGREAL
Returns the cosine of x.
-1.0 <= result <= 1.0
PROCEDURE Tan (x: REAL): REAL
PROCEDURE LTan (x: LONGREAL): LONGREAL
Returns the tangent of x. The Tan and LTan can be computed for all possible REAL and LONGREAL arguments.
PROCEDURE ArcSin (x: REAL): REAL
PROCEDURE LArcSin (x: LONGREAL): LONGREAL
Returns the arcus sine of x.
-1 <= x <= 1
-pi/2 <= result <= pi/2
PROCEDURE ArcCos (x: REAL): REAL
PROCEDURE LArcCos (x: LONGREAL): LONGREAL
Returns the arcus cosine of x.
-1 <= x <= 1
0 <= result <= pi
PROCEDURE ArcTan (x: REAL): REAL
PROCEDURE LArcTan (x: LONGREAL): LONGREAL
Returns the arcus tangent of x.
-pi/2 < result < pi/2
PROCEDURE Sinh (x: REAL): REAL
PROCEDURE LSinh (x: LONGREAL): LONGREAL
Returns the hyperbolic sine of x.
|x| <= ln(MAX(REAL)) (for Sinh)
|x| <= ln(MAX(LONGREAL)) (for LSinh)
PROCEDURE Cosh (x: REAL): REAL
PROCEDURE LCosh (x: LONGREAL): LONGREAL
Returns the hyperbolic cosine of x.
|x| <= ln(MAX(REAL)) (for Cosh)
|x| <= ln(MAX(LONGREAL)) (for LCosh)
1.0 <= result
PROCEDURE Tanh (x: REAL): REAL
PROCEDURE LTanh (x: LONGREAL): LONGREAL
Returns the hyperbolic tangent of x.
-1.0 <= result <= 1.0
PROCEDURE ArcSinh (x: REAL): REAL;
PROCEDURE LArcSinh (x: LONGREAL): LONGREAL;
Returns the inverse hyperbolic sine of x.
PROCEDURE ArcCosh (x: REAL): REAL;
PROCEDURE LArcCosh (x: LONGREAL): LONGREAL;
Returns the inverse hyperbolic cosine of x.
1 <= x
0 <= result
PROCEDURE ArcTanh (x: REAL): REAL;
PROCEDURE LArcTanh (x: LONGREAL): LONGREAL;
Returns the inverse hyperbolic tangent of x.
-1 < x < 1
Below you find the definition of additional trigonometric and hyperbolic functions in terms of the exported functions. The pre and post conditions can be induced from the pre and post conditions of the involved functions.
Cot (x) = 1/Math.Tan(x)
Csc (x) = 1/Math.Sin(x)
Sec (x) = 1/Math.Cos(x)
ArcCot (x) = Math.Pi()/2.0 - Math.ArcTan(x)
ArcCsc (x) = Math.ArcSin(1/x)
ArcSec (x) = Math.ArcCos(1/x)
Coth (x) = 1/Math.Tanh(x)
Csch (x) = 1/Math.Sinh(x)
Sech (x) = 1/Math.Cosh(x)
ArcCoth (x) = Math.ArcTanh(1/x)
ArcCsch (x) = Math.ArcSinh(1/x)
ArcSech (x) = Math.ArcCosh(1/x)
The quadrant-correct arctan function ArcTan2(y, x) which returns the argument of the complex number x + iy in the range (-pi, pi] can be computed with the following procedure:
Returns the maximum or minimum of x and y respectively.
PROCEDURE Sign (x: REAL): REAL
PROCEDURE LSign (x: LONGREAL): LONGREAL
Returns the sign of x, that is 1.0 if x > 0.0, -1.0 if x < 0.0 and 0.0 if x = 0.
result IN {-1.0, 0.0, 1.0}
PROCEDURE Floor (x: REAL): LONGINT
PROCEDURE LFloor (x: LONGREAL): LONGINT
Returns the greatest integer less than or equal to x. This function is identical to ENTIER. Be aware that not all integers greater than 1.0/Eps() can be represented as REAL numbers.
x < MAX(LONGINT)+1 (not explicitly checked)
x >= MIN(LONGINT) (not explicitly checked)
PROCEDURE Ceiling (x: REAL): LONGINT
PROCEDURE LCeiling (x: LONGREAL): LONGINT
Returns the smallest integer greater than or equal to x. Be aware that not all integers greater than 1.0/Eps() can be represented as REAL numbers.
x <= MAX(LONGINT) (not explicitly checked)
x > MIN(LONGINT) (not explicitly checked)
With the function Floor two other prominent functions can be expressed, namely Trunc and Frac. Trunc truncates its argument to the next nearest integer towards zero, and Frac is the fractional part of the argument.
Trunc (x) = Math.Sign(x) * Math.Floor(ABS(x))
Frac (x) = x - Math.Sign(x) * Math.Floor(ABS(x))
With this implementation both functions have the precondition x
MAX(LONGINT) + 1 due to the Floor function.
PROCEDURE Mantissa (x: REAL): REAL
PROCEDURE LMantissa (x: LONGREAL): LONGREAL
Returns the mantissa of x. The mantissa of plus infinity is 1.0, the one of minus infinity is -1.0 and the mantissa of not a number is neither 1.0 nor -1.0.
1.0 <= |result| < 2
PROCEDURE Exponent (x: REAL): LONGINT
PROCEDURE LExponent (x: LONGREAL): LONGINT
Returns the exponent of x such that x = Mantissa(x) * 2Exponent(x). If x represents plus or minus infinity or if x is not a number, then MAX(LONGINT) is returned.